
USE [GrewalCRM_DB]
GO

/****** Object:  StoredProcedure [usp_GetCallsByID]    Script Date: 3/17/2013 8:51:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetCallsByID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetCallsByID];
GO

CREATE PROCEDURE [usp_GetCallsByID]
(
	@CallID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[CallID],
		[CallNo],
		[CallReceiveDate],
		[CallTypeID],
		[DealerID],
		[CustomerID],
		[CallBookedDate],
		[InstallerID],
		[CallAssignedDate],
		[CallCompletedDate],
		[Remarks],
		[CallStatusID],
		[ACBrand],
		[ACParchasedDate],
		[ACModel],
		[ACSerialNo],
		[LastModifiedUser],
		[LastModifiedDateTime]
	FROM [Calls]
	WHERE
		([CallID] = @CallID)

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_GetAllCalls]    Script Date: 3/17/2013 8:51:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetAllCalls]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetAllCalls];
GO

CREATE PROCEDURE [usp_GetAllCalls]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[CallID],
		[CallNo],
		[CallReceiveDate],
		[CallTypeID],
		[DealerID],
		[CustomerID],
		[CallBookedDate],
		[InstallerID],
		[CallAssignedDate],
		[CallCompletedDate],
		[Remarks],
		[CallStatusID],
		[ACBrand],
		[ACParchasedDate],
		[ACModel],
		[ACSerialNo],
		[LastModifiedUser],
		[LastModifiedDateTime]
	FROM [Calls]

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_UpdateCalls]    Script Date: 3/17/2013 8:51:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_UpdateCalls]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_UpdateCalls];
GO

CREATE PROCEDURE [usp_UpdateCalls]
(
	@CallID int,
	@CallNo varchar(50),
	@CallReceiveDate datetime,
	@CallTypeID int,
	@DealerID int,
	@CustomerID int,
	@CallBookedDate datetime = NULL,
	@InstallerID int = NULL,
	@CallAssignedDate datetime = NULL,
	@CallCompletedDate datetime = NULL,
	@Remarks varchar(MAX) = NULL,
	@CallStatusID int = NULL,
	@ACBrand varchar(50),
	@ACParchasedDate datetime,
	@ACModel varchar(50),
	@ACSerialNo varchar(50),
	@LastModifiedUser int,
	@LastModifiedDateTime datetime
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Calls]
	SET
		[CallNo] = @CallNo,
		[CallReceiveDate] = @CallReceiveDate,
		[CallTypeID] = @CallTypeID,
		[DealerID] = @DealerID,
		[CustomerID] = @CustomerID,
		[CallBookedDate] = @CallBookedDate,
		[InstallerID] = @InstallerID,
		[CallAssignedDate] = @CallAssignedDate,
		[CallCompletedDate] = @CallCompletedDate,
		[Remarks] = @Remarks,
		[CallStatusID] = @CallStatusID,
		[ACBrand] = @ACBrand,
		[ACParchasedDate] = @ACParchasedDate,
		[ACModel] = @ACModel,
		[ACSerialNo] = @ACSerialNo,
		[LastModifiedUser] = @LastModifiedUser,
		[LastModifiedDateTime] = @LastModifiedDateTime
	WHERE
		[CallID] = @CallID


	SET @Err = @@Error


	RETURN @Err
END
GO




/****** Object:  StoredProcedure [usp_InsertCalls]    Script Date: 3/17/2013 8:51:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_InsertCalls]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_InsertCalls];
GO

CREATE PROCEDURE [usp_InsertCalls]
(
	@CallID int = NULL output,
	@CallNo varchar(50),
	@CallReceiveDate datetime,
	@CallTypeID int,
	@DealerID int,
	@CustomerID int,
	@CallBookedDate datetime = NULL,
	@InstallerID int = NULL,
	@CallAssignedDate datetime = NULL,
	@CallCompletedDate datetime = NULL,
	@Remarks varchar(MAX) = NULL,
	@CallStatusID int = NULL,
	@ACBrand varchar(50),
	@ACParchasedDate datetime,
	@ACModel varchar(50),
	@ACSerialNo varchar(50),
	@LastModifiedUser int,
	@LastModifiedDateTime datetime
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Calls]
	(
		[CallNo],
		[CallReceiveDate],
		[CallTypeID],
		[DealerID],
		[CustomerID],
		[CallBookedDate],
		[InstallerID],
		[CallAssignedDate],
		[CallCompletedDate],
		[Remarks],
		[CallStatusID],
		[ACBrand],
		[ACParchasedDate],
		[ACModel],
		[ACSerialNo],
		[LastModifiedUser],
		[LastModifiedDateTime]
	)
	VALUES
	(
		@CallNo,
		@CallReceiveDate,
		@CallTypeID,
		@DealerID,
		@CustomerID,
		@CallBookedDate,
		@InstallerID,
		@CallAssignedDate,
		@CallCompletedDate,
		@Remarks,
		@CallStatusID,
		@ACBrand,
		@ACParchasedDate,
		@ACModel,
		@ACSerialNo,
		@LastModifiedUser,
		@LastModifiedDateTime
	)

	SET @Err = @@Error

	SELECT @CallID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_DeleteCalls]    Script Date: 3/17/2013 8:51:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_DeleteCalls]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_DeleteCalls];
GO

CREATE PROCEDURE [usp_DeleteCalls]
(
	@CallID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Calls]
	WHERE
		[CallID] = @CallID
	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_GetCRM_RolesByID]    Script Date: 3/17/2013 8:51:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetCRM_RolesByID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetCRM_RolesByID];
GO

CREATE PROCEDURE [usp_GetCRM_RolesByID]
(
	@RoleID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[RoleID],
		[RoleName],
		[Description]
	FROM [CRM_Roles]
	WHERE
		([RoleID] = @RoleID)

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_GetAllCRM_Roles]    Script Date: 3/17/2013 8:51:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetAllCRM_Roles]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetAllCRM_Roles];
GO

CREATE PROCEDURE [usp_GetAllCRM_Roles]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[RoleID],
		[RoleName],
		[Description]
	FROM [CRM_Roles]

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_UpdateCRM_Roles]    Script Date: 3/17/2013 8:51:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_UpdateCRM_Roles]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_UpdateCRM_Roles];
GO

CREATE PROCEDURE [usp_UpdateCRM_Roles]
(
	@RoleID int,
	@RoleName varchar(50) = NULL,
	@Description varchar(MAX) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [CRM_Roles]
	SET
		[RoleName] = @RoleName,
		[Description] = @Description
	WHERE
		[RoleID] = @RoleID


	SET @Err = @@Error


	RETURN @Err
END
GO




/****** Object:  StoredProcedure [usp_InsertCRM_Roles]    Script Date: 3/17/2013 8:51:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_InsertCRM_Roles]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_InsertCRM_Roles];
GO

CREATE PROCEDURE [usp_InsertCRM_Roles]
(
	@RoleID int = NULL output,
	@RoleName varchar(50) = NULL,
	@Description varchar(MAX) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [CRM_Roles]
	(
		[RoleName],
		[Description]
	)
	VALUES
	(
		@RoleName,
		@Description
	)

	SET @Err = @@Error

	SELECT @RoleID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_DeleteCRM_Roles]    Script Date: 3/17/2013 8:51:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_DeleteCRM_Roles]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_DeleteCRM_Roles];
GO

CREATE PROCEDURE [usp_DeleteCRM_Roles]
(
	@RoleID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [CRM_Roles]
	WHERE
		[RoleID] = @RoleID
	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_GetCRM_UsersByID]    Script Date: 3/17/2013 8:51:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetCRM_UsersByID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetCRM_UsersByID];
GO

CREATE PROCEDURE [usp_GetCRM_UsersByID]
(
	@UserID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[UserID],
		[LoginID],
		[Password],
		[Role],
		[UserName],
		[Address],
		[MobileNo],
		[DOJ],
		[IsActive]
	FROM [CRM_Users]
	WHERE
		([UserID] = @UserID)

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_GetAllCRM_Users]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetAllCRM_Users]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetAllCRM_Users];
GO

CREATE PROCEDURE [usp_GetAllCRM_Users]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[UserID],
		[LoginID],
		[Password],
		[Role],
		[UserName],
		[Address],
		[MobileNo],
		[DOJ],
		[IsActive]
	FROM [CRM_Users]

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_UpdateCRM_Users]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_UpdateCRM_Users]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_UpdateCRM_Users];
GO

CREATE PROCEDURE [usp_UpdateCRM_Users]
(
	@UserID int,
	@LoginID varchar(50),
	@Password nvarchar(50),
	@Role int,
	@UserName varchar(50),
	@Address varchar(MAX) = NULL,
	@MobileNo varchar(10),
	@DOJ datetime,
	@IsActive bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [CRM_Users]
	SET
		[LoginID] = @LoginID,
		[Password] = @Password,
		[Role] = @Role,
		[UserName] = @UserName,
		[Address] = @Address,
		[MobileNo] = @MobileNo,
		[DOJ] = @DOJ,
		[IsActive] = @IsActive
	WHERE
		[UserID] = @UserID


	SET @Err = @@Error


	RETURN @Err
END
GO




/****** Object:  StoredProcedure [usp_InsertCRM_Users]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_InsertCRM_Users]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_InsertCRM_Users];
GO

CREATE PROCEDURE [usp_InsertCRM_Users]
(
	@UserID int = NULL output,
	@LoginID varchar(50),
	@Password nvarchar(50),
	@Role int,
	@UserName varchar(50),
	@Address varchar(MAX) = NULL,
	@MobileNo varchar(10),
	@DOJ datetime,
	@IsActive bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [CRM_Users]
	(
		[LoginID],
		[Password],
		[Role],
		[UserName],
		[Address],
		[MobileNo],
		[DOJ],
		[IsActive]
	)
	VALUES
	(
		@LoginID,
		@Password,
		@Role,
		@UserName,
		@Address,
		@MobileNo,
		@DOJ,
		@IsActive
	)

	SET @Err = @@Error

	SELECT @UserID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_DeleteCRM_Users]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_DeleteCRM_Users]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_DeleteCRM_Users];
GO

CREATE PROCEDURE [usp_DeleteCRM_Users]
(
	@UserID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [CRM_Users]
	WHERE
		[UserID] = @UserID
	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_GetCustomersMasterByID]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetCustomersMasterByID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetCustomersMasterByID];
GO

CREATE PROCEDURE [usp_GetCustomersMasterByID]
(
	@CustomerID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[CustomerID],
		[CustomeName],
		[Address],
		[ZipCode],
		[PhoneNo],
		[MobileNo],
		[LastModifiedUser],
		[LastModifiedDateTime]
	FROM [CustomersMaster]
	WHERE
		([CustomerID] = @CustomerID)

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_GetAllCustomersMaster]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetAllCustomersMaster]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetAllCustomersMaster];
GO

CREATE PROCEDURE [usp_GetAllCustomersMaster]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[CustomerID],
		[CustomeName],
		[Address],
		[ZipCode],
		[PhoneNo],
		[MobileNo],
		[LastModifiedUser],
		[LastModifiedDateTime]
	FROM [CustomersMaster]

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_UpdateCustomersMaster]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_UpdateCustomersMaster]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_UpdateCustomersMaster];
GO

CREATE PROCEDURE [usp_UpdateCustomersMaster]
(
	@CustomerID int,
	@CustomeName varchar(50),
	@Address varchar(MAX),
	@ZipCode varchar(6),
	@PhoneNo varchar(20) = NULL,
	@MobileNo varchar(10) = NULL,
	@LastModifiedUser int,
	@LastModifiedDateTime datetime
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [CustomersMaster]
	SET
		[CustomeName] = @CustomeName,
		[Address] = @Address,
		[ZipCode] = @ZipCode,
		[PhoneNo] = @PhoneNo,
		[MobileNo] = @MobileNo,
		[LastModifiedUser] = @LastModifiedUser,
		[LastModifiedDateTime] = @LastModifiedDateTime
	WHERE
		[CustomerID] = @CustomerID


	SET @Err = @@Error


	RETURN @Err
END
GO




/****** Object:  StoredProcedure [usp_InsertCustomersMaster]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_InsertCustomersMaster]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_InsertCustomersMaster];
GO

CREATE PROCEDURE [usp_InsertCustomersMaster]
(
	@CustomerID int = NULL output,
	@CustomeName varchar(50),
	@Address varchar(MAX),
	@ZipCode varchar(6),
	@PhoneNo varchar(20) = NULL,
	@MobileNo varchar(10) = NULL,
	@LastModifiedUser int,
	@LastModifiedDateTime datetime
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [CustomersMaster]
	(
		[CustomeName],
		[Address],
		[ZipCode],
		[PhoneNo],
		[MobileNo],
		[LastModifiedUser],
		[LastModifiedDateTime]
	)
	VALUES
	(
		@CustomeName,
		@Address,
		@ZipCode,
		@PhoneNo,
		@MobileNo,
		@LastModifiedUser,
		@LastModifiedDateTime
	)

	SET @Err = @@Error

	SELECT @CustomerID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_DeleteCustomersMaster]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_DeleteCustomersMaster]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_DeleteCustomersMaster];
GO

CREATE PROCEDURE [usp_DeleteCustomersMaster]
(
	@CustomerID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [CustomersMaster]
	WHERE
		[CustomerID] = @CustomerID
	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_GetDealersMasterByID]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetDealersMasterByID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetDealersMasterByID];
GO

CREATE PROCEDURE [usp_GetDealersMasterByID]
(
	@DealerID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[DealerID],
		[DealerName],
		[Counter],
		[Address],
		[ContactNo],
		[LastModifiedUser],
		[LastModifiedDateTime]
	FROM [DealersMaster]
	WHERE
		([DealerID] = @DealerID)

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_GetAllDealersMaster]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetAllDealersMaster]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetAllDealersMaster];
GO

CREATE PROCEDURE [usp_GetAllDealersMaster]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[DealerID],
		[DealerName],
		[Counter],
		[Address],
		[ContactNo],
		[LastModifiedUser],
		[LastModifiedDateTime]
	FROM [DealersMaster]

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_UpdateDealersMaster]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_UpdateDealersMaster]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_UpdateDealersMaster];
GO

CREATE PROCEDURE [usp_UpdateDealersMaster]
(
	@DealerID int,
	@DealerName varchar(50),
	@Counter varchar(50),
	@Address varchar(MAX),
	@ContactNo varchar(20) = NULL,
	@LastModifiedUser int,
	@LastModifiedDateTime datetime
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [DealersMaster]
	SET
		[DealerName] = @DealerName,
		[Counter] = @Counter,
		[Address] = @Address,
		[ContactNo] = @ContactNo,
		[LastModifiedUser] = @LastModifiedUser,
		[LastModifiedDateTime] = @LastModifiedDateTime
	WHERE
		[DealerID] = @DealerID


	SET @Err = @@Error


	RETURN @Err
END
GO




/****** Object:  StoredProcedure [usp_InsertDealersMaster]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_InsertDealersMaster]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_InsertDealersMaster];
GO

CREATE PROCEDURE [usp_InsertDealersMaster]
(
	@DealerID int = NULL output,
	@DealerName varchar(50),
	@Counter varchar(50),
	@Address varchar(MAX),
	@ContactNo varchar(20) = NULL,
	@LastModifiedUser int,
	@LastModifiedDateTime datetime
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [DealersMaster]
	(
		[DealerName],
		[Counter],
		[Address],
		[ContactNo],
		[LastModifiedUser],
		[LastModifiedDateTime]
	)
	VALUES
	(
		@DealerName,
		@Counter,
		@Address,
		@ContactNo,
		@LastModifiedUser,
		@LastModifiedDateTime
	)

	SET @Err = @@Error

	SELECT @DealerID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_DeleteDealersMaster]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_DeleteDealersMaster]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_DeleteDealersMaster];
GO

CREATE PROCEDURE [usp_DeleteDealersMaster]
(
	@DealerID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [DealersMaster]
	WHERE
		[DealerID] = @DealerID
	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_GetInatallersMasterByID]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetInatallersMasterByID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetInatallersMasterByID];
GO

CREATE PROCEDURE [usp_GetInatallersMasterByID]
(
	@InstallerID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[InstallerID],
		[InstallerName],
		[Address],
		[PhoneNo],
		[MobileNo],
		[LastModifiedUser],
		[LastModifiedDateTime]
	FROM [InatallersMaster]
	WHERE
		([InstallerID] = @InstallerID)

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_GetAllInatallersMaster]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetAllInatallersMaster]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetAllInatallersMaster];
GO

CREATE PROCEDURE [usp_GetAllInatallersMaster]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[InstallerID],
		[InstallerName],
		[Address],
		[PhoneNo],
		[MobileNo],
		[LastModifiedUser],
		[LastModifiedDateTime]
	FROM [InatallersMaster]

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_UpdateInatallersMaster]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_UpdateInatallersMaster]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_UpdateInatallersMaster];
GO

CREATE PROCEDURE [usp_UpdateInatallersMaster]
(
	@InstallerID int,
	@InstallerName varchar(50),
	@Address varchar(MAX),
	@PhoneNo varchar(20) = NULL,
	@MobileNo varchar(10),
	@LastModifiedUser int,
	@LastModifiedDateTime datetime
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [InatallersMaster]
	SET
		[InstallerName] = @InstallerName,
		[Address] = @Address,
		[PhoneNo] = @PhoneNo,
		[MobileNo] = @MobileNo,
		[LastModifiedUser] = @LastModifiedUser,
		[LastModifiedDateTime] = @LastModifiedDateTime
	WHERE
		[InstallerID] = @InstallerID


	SET @Err = @@Error


	RETURN @Err
END
GO




/****** Object:  StoredProcedure [usp_InsertInatallersMaster]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_InsertInatallersMaster]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_InsertInatallersMaster];
GO

CREATE PROCEDURE [usp_InsertInatallersMaster]
(
	@InstallerID int = NULL output,
	@InstallerName varchar(50),
	@Address varchar(MAX),
	@PhoneNo varchar(20) = NULL,
	@MobileNo varchar(10),
	@LastModifiedUser int,
	@LastModifiedDateTime datetime
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [InatallersMaster]
	(
		[InstallerName],
		[Address],
		[PhoneNo],
		[MobileNo],
		[LastModifiedUser],
		[LastModifiedDateTime]
	)
	VALUES
	(
		@InstallerName,
		@Address,
		@PhoneNo,
		@MobileNo,
		@LastModifiedUser,
		@LastModifiedDateTime
	)

	SET @Err = @@Error

	SELECT @InstallerID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_DeleteInatallersMaster]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_DeleteInatallersMaster]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_DeleteInatallersMaster];
GO

CREATE PROCEDURE [usp_DeleteInatallersMaster]
(
	@InstallerID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [InatallersMaster]
	WHERE
		[InstallerID] = @InstallerID
	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_GetReff_CallTypeByID]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetReff_CallTypeByID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetReff_CallTypeByID];
GO

CREATE PROCEDURE [usp_GetReff_CallTypeByID]
(
	@CallTypeID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[CallTypeID],
		[CallTypeName],
		[Description]
	FROM [Reff_CallType]
	WHERE
		([CallTypeID] = @CallTypeID)

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_GetAllReff_CallType]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetAllReff_CallType]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetAllReff_CallType];
GO

CREATE PROCEDURE [usp_GetAllReff_CallType]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[CallTypeID],
		[CallTypeName],
		[Description]
	FROM [Reff_CallType]

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_UpdateReff_CallType]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_UpdateReff_CallType]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_UpdateReff_CallType];
GO

CREATE PROCEDURE [usp_UpdateReff_CallType]
(
	@CallTypeID int,
	@CallTypeName varchar(50) = NULL,
	@Description varchar(MAX) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Reff_CallType]
	SET
		[CallTypeName] = @CallTypeName,
		[Description] = @Description
	WHERE
		[CallTypeID] = @CallTypeID


	SET @Err = @@Error


	RETURN @Err
END
GO




/****** Object:  StoredProcedure [usp_InsertReff_CallType]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_InsertReff_CallType]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_InsertReff_CallType];
GO

CREATE PROCEDURE [usp_InsertReff_CallType]
(
	@CallTypeID int = NULL output,
	@CallTypeName varchar(50) = NULL,
	@Description varchar(MAX) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Reff_CallType]
	(
		[CallTypeName],
		[Description]
	)
	VALUES
	(
		@CallTypeName,
		@Description
	)

	SET @Err = @@Error

	SELECT @CallTypeID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_DeleteReff_CallType]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_DeleteReff_CallType]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_DeleteReff_CallType];
GO

CREATE PROCEDURE [usp_DeleteReff_CallType]
(
	@CallTypeID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Reff_CallType]
	WHERE
		[CallTypeID] = @CallTypeID
	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_GetReff_StatusByID]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetReff_StatusByID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetReff_StatusByID];
GO

CREATE PROCEDURE [usp_GetReff_StatusByID]
(
	@StatusID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[StatusID],
		[StatusName],
		[Description]
	FROM [Reff_Status]
	WHERE
		([StatusID] = @StatusID)

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_GetAllReff_Status]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_GetAllReff_Status]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_GetAllReff_Status];
GO

CREATE PROCEDURE [usp_GetAllReff_Status]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[StatusID],
		[StatusName],
		[Description]
	FROM [Reff_Status]

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_UpdateReff_Status]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_UpdateReff_Status]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_UpdateReff_Status];
GO

CREATE PROCEDURE [usp_UpdateReff_Status]
(
	@StatusID int,
	@StatusName varchar(50) = NULL,
	@Description varchar(MAX) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Reff_Status]
	SET
		[StatusName] = @StatusName,
		[Description] = @Description
	WHERE
		[StatusID] = @StatusID


	SET @Err = @@Error


	RETURN @Err
END
GO




/****** Object:  StoredProcedure [usp_InsertReff_Status]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_InsertReff_Status]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_InsertReff_Status];
GO

CREATE PROCEDURE [usp_InsertReff_Status]
(
	@StatusID int = NULL output,
	@StatusName varchar(50) = NULL,
	@Description varchar(MAX) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Reff_Status]
	(
		[StatusName],
		[Description]
	)
	VALUES
	(
		@StatusName,
		@Description
	)

	SET @Err = @@Error

	SELECT @StatusID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [usp_DeleteReff_Status]    Script Date: 3/17/2013 8:51:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[usp_DeleteReff_Status]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [usp_DeleteReff_Status];
GO

CREATE PROCEDURE [usp_DeleteReff_Status]
(
	@StatusID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Reff_Status]
	WHERE
		[StatusID] = @StatusID
	SET @Err = @@Error

	RETURN @Err
END
GO

